package com.mjk.common.tools.lambada.impl;


import com.mjk.common.tools.lambada.LambdaMeta;

public class ShadowLambdaMeta implements LambdaMeta {
    private final SerializedLambda lambda;

    public ShadowLambdaMeta(SerializedLambda lambda) {
        this.lambda = lambda;
    }

    @Override
    public String getImplMethodName() {
        return lambda.getImplMethodName();
    }

    @Override
    public Class<?> getInstantiatedClass() {
        String instantiatedMethodType = lambda.getInstantiatedMethodType();
        String instantiatedType = instantiatedMethodType.substring(2, instantiatedMethodType.indexOf(";")).replace("/", ".");
        try {
            return lambda.getCapturingClass().getClassLoader().loadClass(instantiatedType);
        }catch(Exception e){
            return null;
        }
    }
}
